package com.ruoyi.common.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class CommonRpc
{
    public static void main(String[] args)
    {
        // 初始化acsClient,<accessKeyId>和"<accessSecret>"在短信控制台查询即可。
        DefaultProfile profile = DefaultProfile.getProfile("ap-southeast-1", "LTAI4G7YaiXTECS5T6hj6Xfg", "oH2xeQ2K8jqbTaRX4FG24Pb5gNV2Xm");
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        // 域名，请勿修改
        request.setDomain("dysmsapi.ap-southeast-1.aliyuncs.com");
        // API版本号，请勿修改
        request.setVersion("2018-05-01");
        // API名称
        request.setAction("SendMessageWithTemplate");
        // 接收号码，格式为：国际码+号码，必填
        request.putQueryParameter("To", "8618981722787");
        request.putQueryParameter("From", "智享久链");
        request.putQueryParameter("TemplateCode", "SMS_189300047");
        request.putQueryParameter("TemplateParam", "{\"code\":\"1234\"}");
        request.putQueryParameter("SmsUpExtendCode", "12345");
        try
        {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        }
        catch (ServerException e)
        {
            e.printStackTrace();
        }
        catch (ClientException e)
        {
            e.printStackTrace();
        }
    }
}
